package com.dragon.repository.domain.vo;

import com.dragon.common.model.Update;
import com.dragon.common.util.BeanUtils;
import com.dragon.repository.entity.Stock;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * @author sy
 */
@Data
@ApiModel(value = "")
public class StockVO {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "主id")
    private Integer id;

    @ApiModelProperty(value = "仓库id")
    private Integer warehouseId;

    @ApiModelProperty(value = "产品sku_id")
    private Integer productSkuId;

    @ApiModelProperty(value = "计量单位id")
    private Integer unitId;

    @ApiModelProperty(value = "原有数量")
    private Double quantity;

//    @ApiModelProperty(value = "剩下的数量")
//    private BigDecimal leftoverNum;

    @ApiModelProperty(value = "公司id")
    private Integer companyId;

    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    @ApiModelProperty(value = "修改时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;

    @ApiModelProperty(value = "仓库名称")
    private String warehouseName;

    @ApiModelProperty(value = "规格名称")
    private String specificationName;

    @ApiModelProperty(value = "产品名称")
    private String productName;

    @ApiModelProperty(value = "单位名称")
    private String unitName;

    @ApiModelProperty(value = "类别名称")
    private String categoryName;

    @ApiModelProperty(value = "类别id")
    private Integer categoryId;


    @NotNull(groups = Update.class,message = "主键不能为空")
    public static Stock convert(StockVO vo) {
        Stock entity = new Stock();
        BeanUtils.copyProperties(vo,entity);
        return entity;
    }
    public static List<Stock> convertList(List<StockVO> list) {
        List<Stock> resultList = new ArrayList<>();
        for (StockVO vo : list) {
            resultList.add(convert(vo));
        }
        return resultList;
    }
}
